//
//  MoboViewController.m
//  Moboplayer
//
//  Created by lmx on 16/6/8.
//  Copyright © 2016年 lmx. All rights reserved.
//

#import "MoboViewController.h"
#import <QuartzCore/QuartzCore.h>
#import <Foundation/Foundation.h>
#import "MoboHardViewController.h"
#import "MoboSoftViewController.h"
#import "libavformat/avformat.h"
#import <AVFoundation/AVAnimation.h>

//extern AVPicture *get_rgb24_picture(const char *file, int gen_second, int width, int height, int *org_width, int *org_height);


//static NSString * formatTimeInterval(CGFloat seconds, BOOL isLeft)
//{
//    seconds = MAX(0, seconds);
//    
//    NSInteger s = seconds;
//    NSInteger m = s / 60;
//    NSInteger h = m / 60;
//    
//    s = s % 60;
//    m = m % 60;
//    
//    NSMutableString *format = [(isLeft && seconds >= 0.5 ? @"-" : @"") mutableCopy];
//    if (h != 0) [format appendFormat:@"%ld:%0.2ld", (long)h, (long)m];
//    else        [format appendFormat:@"%ld", (long)m];
//    [format appendFormat:@":%0.2ld", (long)s];
//    
//    return format;
//}


enum {
    
    MoboPlayerInfoSectionGeneral,
    MoboPlayerInfoSectionVideo,
    MoboPlayerInfoSectionAudio,
    MoboPlayerInfoSectionSubtitles,
    MoboPlayerInfoSectionMetadata,
    MoboPlayerInfoSectionCount,
};

enum {
    
    MoboPlayerInfoGeneralFormat,
    MoboPlayerInfoGeneralBitrate,
    MoboPlayerInfoGeneralCount,
};

//#define LOCAL_MIN_BUFFERED_DURATION   0.1
//#define LOCAL_MAX_BUFFERED_DURATION   2.0
//#define NETWORK_MIN_BUFFERED_DURATION 2.0
//#define NETWORK_MAX_BUFFERED_DURATION 4.0

@interface MoboViewController ()
{

    MoboHardViewController *_hardController;
    MoboSoftViewController *_softController;
    
    
    BOOL _autoChange;
    int _appear;
}

@end

@implementation MoboViewController

@synthesize DecodeMode  = _DecodeMode;
@synthesize moboPlayer  = _moboPlayer;
@synthesize FilePath    = _FilePath;



- (void)viewDidLoad {
    [super viewDidLoad];
    
    _autoChange =false;
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (CGRect)getScreenFrameForCurrentOrientation {
    return [self getScreenFrameForOrientation:[UIApplication sharedApplication].statusBarOrientation];
}

- (CGRect)getScreenFrameForOrientation:(UIInterfaceOrientation)orientation {

    UIScreen *screen = [UIScreen mainScreen];
    CGRect fullScreenRect = screen.bounds;
  //  BOOL statusBarHidden = [UIApplication sharedApplication].statusBarHidden;
    
//    implicitly in Portrait orientation.
    if(orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft){
        CGRect temp = CGRectZero;
        temp.size.width = fullScreenRect.size.width;
        temp.size.height = fullScreenRect.size.height;
        fullScreenRect = temp;
    } else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        
        CGRect temp = CGRectZero;
        temp.size.width = fullScreenRect.size.height ;
        temp.size.height =fullScreenRect.size.width;
        fullScreenRect = temp;
    }
    return fullScreenRect;
}
- (void) didRotate:(NSNotification *)notification
{
    NSLog(@"null ");
    CGRect frame;
    frame = [self getScreenFrameForCurrentOrientation];
}

-(id) hardMovieViewControllerWithContentPath: (NSString *) path
                                  parameters: (NSDictionary *) parameters;
{

    
     return self;
}
- (id) softMovieViewControllerWithContentPath: (NSString *) path
                                   parameters: (NSDictionary *) parameters;
{
    _FilePath = path;
    _softController = [MoboSoftViewController movieViewControllerWithContentPath:_FilePath parameters:NULL];
   CGRect frame = [self getScreenFrameForCurrentOrientation];
    _softController.view.frame = frame;
    _softController.view.center =self.view.center;
    _softController.Player_Speed = 1.0;
    _moboPlayer = _softController;
    self.DecodeMode = SOFT_DECODE;
    [self.view insertSubview:_softController.view atIndex:0];
    return self;
}
-(void) closecurrentfile
{
    [self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    _softController = NULL;
}

@end
